﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved All Rights Reserved All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System;
using System.Collections.Generic;
using System.Linq;

namespace FinPlusAssembler
{
    public static class DictionaryExtension
    {
        public static string DictToString(this IDictionary<string, string[]> value, char delimiter = '%', string brackets = "{}")
        {
            var b = brackets.ToCharArray();
            if (b.Length != 2)
                throw new FormatException("incorrect bracket format should be 2 char string");

            var res = string.Join(delimiter.ToString(), value.Select(k => string.Format("{0}{1}{2}{3}{4}{5}{6}", b[0],
                k.Key.ToString(), delimiter, b[0], string.Join(delimiter.ToString(), k.Value), b[1], b[1])).ToArray());

            return string.Format("{0}{1}{2}", b[0], res, b[1]);
        }
    }
}
